<?php

namespace App\Http\Controllers\Common;

use App\Http\Controllers\Controller;
use App\Models\Tools\Data;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class EnumsController extends Controller
{

    public function index()
    {

        $all = $this->all;
        $type = $all['type'];
        $result = [];

        try{
            switch ($type) {
                case 'course': // 课程
                    $courses = DB::table('laifei_sys_course')->get()->toArray();
                    $courses = json_decode(json_encode($courses),true);
                    foreach ($courses as $key => $value){
                        $result[] = ['label'=>$value['title'], 'value'=>$value['course_id']];
                    }
                    break;
                case 'explore_channel': // 渠道
                    $result = DB::table('explore_channel')
                        ->select('channel_id as value','channel_name as text')
                        ->get()
                        ->toArray();
                    break;
                case 'explore_channels': // 达人等级(包含任意)
                    $result = DB::table('explore_channel')
                        ->select('channel_id as value','channel_name as text')
                        ->get()
                        ->toArray();
                    array_unshift($result,['value'=>0,'text'=>'任意等级']);
                    break;
                case 'explore_channels_buy': // 购买服务等级
                    $result = DB::table('explore_channel')
                        ->select('channel_id as id','channel_name as name')
                        ->get()
                        ->toArray();
                    break;
                case 'explore_channels_list': // 购买服务等级（价格）
                    $result = DB::table('explore_channel')
                        ->select('channel_id as id','price','channel_id as s1')
                        ->get()
                        ->map(function ($item){
                            $item->stock_num = 10000;
                            return $item;
                        })
                        ->toArray();
                    break;
                case 'laifei_shop_types': // 店铺类型
                    $channels = Data::$laifeiShopTypes;
                    foreach($channels as $key=>$value){
                        $result[] = ['value'=>$key,'text'=>$value];
                    }
                    break;
                case 'explore_order_status': // 订单流程
                    $works = Data::$exploreOrderStatus;
                    foreach($works as $key=>$value){
                        $result[] = ['value'=>$key,'text'=>$value];
                    }
                    break;
                case 'explore_work_status': // 工单流程
                    $works = Data::$exploreWorkStatus;
                    foreach($works as $key=>$value){
                        $result[] = ['value'=>$key,'text'=>$value];
                    }
                    break;
                case 'explore_work_action': // 工单操作
                    $actions = Data::$exploreWorkAction;
                    foreach($actions as $key=>$value){
                        $result[] = ['value'=>$key,'text'=>$value];
                    }
                    break;
                default:
                    return $this->setReturnJson(-1,'未找到信息');
            }
        }catch (\Exception $e){
            Log::error(EnumsController::class,['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'查询失败');
        }
        return $this->setReturnJson(0, 'success', $result);
    }

}
